home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / progem.lzh / apndx1.prf next >
Text File  |  1987-06-23  |  5KB  |  193 lines

  1. .!****************************************************************************
  2. .! 
  3. .! ANTIC PUBLISHING INC., COPYRIGHT 1985.  REPRINTED BY PERMISSION.
  4. .!
  5. .! ** Professional GEM ** by Tim Oren
  6. .!
  7. .! Proff File by ST enthusiasts at
  8. .! Case Western Reserve University
  9. .! Cleveland, Ohio
  10. .! uucp : decvax!cwruecmp!bammi
  11. .! csnet: bammi@case
  12. .! arpa : bammi%case@csnet-relay
  13. .! compuserve: 71515,155
  14. .!
  15. .!****************************************************************************
  16. .!
  17. .!            Begin Appendix 1
  18. .!
  19. .!***************************************************************************
  20. .!
  21. .!
  22. .AP I Sample Code for Part II
  23. /* >>>>>>>>>>>>>>>>>>>>>>>>> Sample Redraw Code <<<<<<<<<<<<<<<<<<<<<<<<<<< */
  24.  
  25. VOID
  26. do_redraw(wh, area)        /* wh = window handle from msg[3] */
  27. WORD    wh;        /* area = pointer to redraw rect- */
  28. GRECT    *area;        /*   tangle in msg[4] thru msg[7] */
  29. {
  30.     GRECT    box;
  31.     
  32.     graf_mouse(M_OFF, 0x0L);
  33.     wind_update(BEG_UPDATE);
  34.     
  35.     wind_get(wh, WF_FIRSTXYWH, &box.g_x, &box.g_y, &box.g_w, &box.g_h);
  36.     while ( box.g_w && box.g_h )
  37.     {
  38.         if (rc_intersect(full, &box))      /* Full is entire screen */
  39.             if (rc_intersect(area, &box))
  40.             {
  41.                 if (wh == w1_handle)      /* Test for window 1 handle */
  42.                 {          /* AES redraw example          */
  43.                     objc_draw(w1_tree, ROOT, MAX_DEPTH, box.g_x, 
  44.                           box.g_y, box.g_w, box.g_h);
  45.                 }
  46.                 else if (wh == w2_handle) /* Test for window 2 handle */
  47.                 {          /* VDI redraw example          */
  48.                     set_clip(TRUE, &box);
  49.                     /*  Put VDI drawing calls here */
  50.                 }
  51.                 /* add more windows here */
  52.             }
  53.         wind_get(wh, WF_NEXTXYWH, &box.g_x, &box.g_y, &box.g_w, 
  54.              &box.g_h);
  55.     }
  56.     
  57.     wind_update(END_UPDATE);
  58.     graf_mouse(M_ON, 0x0L);
  59. }
  60. .bp
  61. /* >>>>>>>>>>>>>>>>>>>>>>>> Utilities used in do_redraw <<<<<<<<<<<<<<<<<<<< */
  62.  
  63. VOID
  64. set_clip(clip_flag, area)    /* set clip to specified area    */
  65. WORD    clip_flag;
  66. GRECT    *area;
  67. {
  68.     WORD    pxy[4];
  69.     
  70.     grect_to_array(area, pxy);
  71.     vs_clip(vdi_handle, clip_flag, pxy);
  72. }
  73.  
  74. VOID
  75. grect_to_array(area, array)    /* convert x,y,w,h to upr lt x,y and    */
  76. GRECT    *area;        /*              lwr rt x,y    */
  77. WORD    *array;
  78. {
  79.     *array++ = area->g_x;
  80.     *array++ = area->g_y;
  81.     *array++ = area->g_x + area->g_w - 1;
  82.     *array = area->g_y + area->g_h - 1;
  83. }
  84.  
  85. WORD
  86. rc_intersect(p1, p2)        /* compute intersect of two rectangles    */
  87. GRECT    *p1, *p2;
  88. {
  89.     WORD    tx, ty, tw, th;
  90.     
  91.     tw = min(p2->g_x + p2->g_w, p1->g_x + p1->g_w);
  92.     th = min(p2->g_y + p2->g_h, p1->g_y + p1->g_h);
  93.     tx = max(p2->g_x, p1->g_x);
  94.     ty = max(p2->g_y, p1->g_y);
  95.     p2->g_x = tx;
  96.     p2->g_y = ty;
  97.     p2->g_w = tw - tx;
  98.     p2->g_h = th - ty;
  99.     return( (tw > tx) && (th > ty) );
  100. }
  101. .bp
  102. /* >>>>>>>>>>>>>>>>>>>>>>> "Self-redraw" Utility <<<<<<<<<<<<<<<<<<<<<<<<< */
  103.  
  104. VOID
  105. send_redraw(wh, p)
  106. WORD    wh;
  107. GRECT    *p;
  108. {
  109.     WORD    msg[8];
  110.     
  111.     msg[0] = WM_REDRAW;        /* Defined in GEMBIND.H        */
  112.     msg[1] = gl_apid;        /* As returned by appl_init */
  113.     msg[2] = 0;
  114.     msg[3] = wh;            /* Handle of window to redraw */
  115.     msg[4] = p->g_x;
  116.     msg[5] = p->g_y;
  117.     msg[6] = p->g_w;
  118.     msg[7] = p->g_h;
  119.     appl_write(gl_apid, 16, &msg);    /* Use ADDR(msg) for portability */
  120. }
  121. .bp
  122. /* >>>>>>>>>>>>>>>>>>>> Utilities for Window Requests <<<<<<<<<<<<<<<<<< */
  123.  
  124. VOID
  125. rc_constrain(pc, pt)
  126. GRECT        *pc;
  127. GRECT        *pt;
  128. {
  129.     if (pt->g_x < pc->g_x)
  130.         pt->g_x = pc->g_x;
  131.     if (pt->g_y < pc->g_y)
  132.         pt->g_y = pc->g_y;
  133.     if ((pt->g_x + pt->g_w) > (pc->g_x + pc->g_w))
  134.         pt->g_x = (pc->g_x + pc->g_w) - pt->g_w;
  135.     if ((pt->g_y + pt->g_h) > (pc->g_y + pc->g_h))
  136.         pt->g_y = (pc->g_y + pc->g_h) - pt->g_h;
  137. }
  138.  
  139. WORD
  140. align(x,n)        /* Snap position x to an n-bit grid         */ 
  141. WORD     x, n;   /* Use n = 16 for horizontal word alignment */
  142. {
  143.     x += (n >> 2) - 1;        /* Round and... */
  144.     x = n * (x / n);        /* remove residue */
  145.     return (x);
  146. }    
  147. .bp
  148. /* >>>>>>>>>>>>>>>>>>>>>>> Window full utility <<<<<<<<<<<<<<<<<<<<<<< */
  149.  
  150. VOID
  151. hndl_full(wh)        /* depending on current window state, make window    */
  152. WORD    wh;    /*   full size -or- return to previous shrunken size */
  153. {        /* graf_ calls are optional special effects.         */
  154.     GRECT    prev;
  155.     GRECT    curr;
  156.     GRECT    full;
  157.     
  158.     wind_get(wh, WF_CXYWH, &curr.g_x, &curr.g_y, &curr.g_w, &curr.g_h);
  159.     wind_get(wh, WF_PXYWH, &prev.g_x, &prev.g_y, &prev.g_w, &prev.g_h);
  160.     wind_get(wh, WF_FXYWH, &full.g_x, &full.g_y, &full.g_w, &full.g_h);
  161.     if ( rc_equal(&curr, &full) )
  162.     {        /* Is full, change to previous         */
  163.         graf_shrinkbox(prev.g_x, prev.g_y, prev.g_w, prev.g_h,
  164.                    full.g_x, full.g_y, full.g_w, full.g_h);
  165.         wind_set(wh, WF_CXYWH, prev.g_x, prev.g_y, prev.g_w, prev.g_h);
  166.         /* put send_redraw here if you need it */
  167.     }
  168.     else
  169.     {        /* is not full, so set to full        */
  170.         graf_growbox(curr.g_x, curr.g_y, curr.g_w, curr.g_h,
  171.                  full.g_x, full.g_y, full.g_w, full.g_h);
  172.         wind_set(wh, WF_CXYWH, full.g_x, full.g_y, full.g_w, full.g_h);
  173.     }
  174. }
  175.  
  176. WORD
  177. rc_equal(p1, p2)        /* tests for two rectangles equal    */
  178. GRECT    *p1, *p2;
  179. {
  180.     if ((p1->g_x != p2->g_x) ||
  181.         (p1->g_y != p2->g_y) ||
  182.         (p1->g_w != p2->g_w) ||
  183.         (p1->g_h != p2->g_h))
  184.         return(FALSE);
  185.     return(TRUE);
  186. }
  187. .!
  188. .!****************************************************************************
  189. .!
  190. .!            End Appendix 1
  191. .!
  192. .!****************************************************************************
  193.